from bs4 import BeautifulSoup
import requests
import time

'''
异步获取数据 【使用ajax获取数据】
'''
url = 'https://knewone.com/discover?page='
info = []


def get_page(send_url):
    '''
    获取页数据
    :param send_url: 请求链接
    :return:
    '''
    wb_data = requests.get(send_url)
    soup = BeautifulSoup(wb_data.text, 'lxml')
    images = soup.select('a.cover-inner > img')
    titles = soup.select('section.content > h4 > a')
    links = soup.select('section.content > h4 > a')

    for image_item, title_item, link_item in zip(images, titles, links):
        data = {
            'image': image_item.get('src'),
            'title': title_item.getText(),
            'link': link_item.get('href')
        }
        info.append(data)


def get_more_pages(start, end):
    for index in range(start, end):
        get_page(url + str(index))
        time.sleep(2)


get_more_pages(1, 3)

print(1)
print(info)
